home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue51 / Observer / FObserver_BarGraph.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-10-08  |  2.4 KB  |  94 lines

  1. {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2.   (c) TechInsite Pty. Ltd.
  3.   PO Box 429, Abbotsford, Melbourne. 3067 Australia
  4.   Phone: +61 3 9419 6456
  5.   Fax:   +61 3 9419 1682
  6.   Web:   www.techinsite.com.au
  7.   EMail: peter_hinrichsen@techinsite.com.au
  8.  
  9.   Created: October 1999
  10.  
  11.   Notes: Show the subject as a bar graph
  12.  
  13. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  14. unit FObserver_BarGraph;
  15.  
  16. interface
  17.  
  18. uses
  19.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  20.   StdCtrls, TeEngine, Series, ExtCtrls, TeeProcs, Chart,
  21.   FObserver_Abstract;
  22.  
  23. type
  24.  
  25.   //--------------------------------------------------------
  26.   TFormObserverBarGraph = class(TFormObserverAbstract)
  27.     Chart1: TChart;
  28.     Series1: TBarSeries;
  29.     procedure FormCreate(Sender: TObject);
  30.   private
  31.     // Get a unique colour to show in the graph
  32.     function  GetColour( const pI : integer ) : TColor ;
  33.   public
  34.     // Override the virtual abstract DataToObserver method
  35.     procedure DataToObserver ; override ;
  36.   end;
  37.  
  38. implementation
  39. uses
  40.   // To give access to the TStockTrans so
  41.   // we can access data in the subject
  42.   Subject_Portfolio
  43.   ;
  44.  
  45. {$R *.DFM}
  46.  
  47. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  48. // *
  49. // * TFormViewBarGraph
  50. // *
  51. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  52. procedure TFormObserverBarGraph.DataToObserver ;
  53. var
  54.   i           : integer ;
  55.   lStockTrans : TStockTrans ;
  56. begin
  57.   chart1.series[0].clear ;
  58.   with Subject as TPortfolio do begin
  59.     for i := 0 to Stocks.Count - 1 do begin
  60.       lStockTrans := Stocks.Items[ i ] ;
  61.       chart1.series[0].add( lStockTrans.Value,
  62.                             lStockTrans.StockCode,
  63.                             GetColour( i ))  ;
  64.     end ;
  65.   end ;
  66. end;
  67.  
  68. //----------------------------------------------------------
  69. procedure TFormObserverBarGraph.FormCreate(Sender: TObject);
  70. begin
  71.   inherited;
  72.   // Save a pointer into the subject
  73.   Subject := gPortfolio ;
  74. end;
  75.  
  76. // Get a unique colour to display in the graph
  77. //----------------------------------------------------------
  78. function TFormObserverBarGraph.GetColour(const pI:
  79.                                            integer): TColor;
  80. begin
  81.   case pI of
  82.     0 : result := clRed ;
  83.     1 : result := clBlue ;
  84.     2 : result := clGreen ;
  85.     3 : result := clYellow ;
  86.     4 : result := clAqua ;
  87.   else
  88.     result := clBlack ;
  89.   end ;
  90. end;
  91.  
  92. end.
  93.  
  94.